package com.tencent.yumeko;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/producer")
public class ProducerController {
    private static Logger LOG = LoggerFactory.getLogger(ProducerController.class);

    @Value("${server.port:0}")
    private int port;

    /**
     * Get information of callee.
     * @return information of producer
     */
    //http://localhost:11111/producer/info
    @GetMapping("/info")
    public String info() {
        LOG.info("这个 [{}] 端口被远程呼叫了.", port);
        return String.format("Discovery Service producer [%s] is called.", port);
    }

    /**
     * Get sum of two value.
     * @param value1 value 1
     * @param value2 value 2
     * @return sum
     */
    //http://localhost:11111/producer/sum?value1=2&value2=2
    @GetMapping("/sum")
    public int sum(@RequestParam int value1, @RequestParam int value2) {
        LOG.info("俩个数据之和为 {}.", value1 + value2);
        return value1 + value2;
    }
}
